package com.yunkeji.api.auth.processor.login;

import cn.hutool.extra.spring.SpringUtil;
import com.yunkeji.api.auth.bo.ToLoginBo;
import com.yunkeji.api.auth.processor.service.LoginFactory;
import com.yunkeji.api.auth.processor.service.LoginStrategy;
import com.yunkeji.api.auth.service.AuthService;
import com.yunkeji.api.auth.vo.ToLoginVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 验证码登录
 *
 * @author 老张
 */
@Component
@Slf4j
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SmsCodeLogin implements InitializingBean, LoginStrategy {
    private final AuthService authService;
    private static String EVN = SpringUtil.getActiveProfile();

    @Override
    public ToLoginVo execute(ToLoginBo bo) {
        // 验证码登录
        return authService.toLogin(bo, "prod".equalsIgnoreCase(EVN));
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        LoginFactory.put(ToLoginBo.LoginType.验证码登录, this);
    }
}
